﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using quanlynhasach;

namespace quanlynhasach.Linksql
{
    class KhachHangsql
    {
        Connection db = new Connection();
        Nhanvien nv = new Nhanvien();

        

        public DataTable getKH(string maKH)
        {
            return db.getDS("Select * from KhachHang where MaKH = '" + maKH + "'");
        }

        public DataTable getKH()
        {
            return db.getDS("Select MaKH,TenKH,NgaySinh,GioiTinh,DiaChi,SoDT,SoCMND,Email from KhachHang where MaKH <> 'N/A'");
        }

        public bool check(string makh)
        {
            if (db.getDS("Select * from KhachHang where MaKH = '" + makh + "'").Rows.Count > 0)
                return true;
            return false;
        }
        public bool XoaKH(string makh)
        {
            string[] param = { "@MaKH" };
            object[] value = { makh };
            string query = "Delete from KhachHang where MaKH=@MaKH";
            return db.ExecuteNonQueryPara(query, param, value);
        }

        public bool SuaKH(KhachHang kh)
        {
            string[] param ={"@MaKH","@TenKH","@NgaySinhKH","@GioiTinhKH","@DiaChiKH",
                           "@SoDienThoaiKH","@SoCMNDKH","@EmailKH"};
            object[] value = { kh.MaKH,kh.TenKH, kh.NgaySinhKH, kh.GioiTinhKH, kh.DiaChiKH, kh.SoDienThoaiKH, kh.SoCMNDKH,
                             kh.EmailKH};
            string query = "Update KhachHang"
                           + " set TenKH=@TenKH,NgaySinh=@NgaySinhKH,GioiTinh=@GioiTinhKH,DiaChi=@DiaChiKH,"
                           + "SoDT=@SoDienThoaiKH,SoCMND=@SoCMNDKH,Email=@EmailKH"
                           + " where MaKH=@MaKH";
            return db.ExecuteNonQueryPara(query, param, value);
        }

        public bool ThemKH(KhachHang kh)
        {
            string[] param ={"@MaKH","@TenKH","@NgaySinhKH","@GioiTinhKH","@DiaChiKH",
                           "@SoDienThoaiKH","@SoCMNDKH","@EmailKH"};
            object[] value = {kh.MaKH, kh.TenKH, kh.NgaySinhKH, kh.GioiTinhKH, kh.DiaChiKH, kh.SoDienThoaiKH, kh.SoCMNDKH,
                             kh.EmailKH};
            string query = "Insert into KhachHang"
                           + "(MaKH,TenKH,NgaySinh,GioiTinh,DiaChi,SoDT,SoCMND,Email)"
                           + " values (@MaKH,@TenKH,@NgaySinhKH,@GioiTinhKH,@DiaChiKH,@SoDienThoaiKH,@SoCMNDKH,@EmailKH)";
            return db.ExecuteNonQueryPara(query, param, value);
        }

        
    }
}
